package com.example.roadeyeserver.enums;

import com.example.roadeyeserver.entity.vo.HolidayVO;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public enum HolidayEnum {

    NEW_YEAR_DAY("元旦", 1, false),
    SPRING_FESTIVAL("春节", 2, true),
    QING_MING("清明", 3, true),
    LABOUR_DAY("劳动节", 4, true),
    DRAGON_BOAT_FESTIVAL("端午节", 5, false),
    MID_AUTUMN_FESTIVAL("中秋节", 6, false),
    NATIONAL_DAY("国庆节", 7, true);

    // 节假日名称
    private final String name;
    // 节假日类型
    private final Integer type;
    // 是否免费通行
    private final Boolean freePass;

    HolidayEnum(String name, Integer type, Boolean freePass) {
        this.name = name;
        this.type = type;
        this.freePass = freePass;
    }

    public String getName() {
        return name;
    }

    public Integer getType() {
        return type;
    }

    public Boolean getFreePass() {
        return freePass;
    }

    /**
     * 获取所有节假日
     * @return
     */
    public static List<HolidayVO> getHolidayList() {
        List<HolidayVO> holidayList = new ArrayList<>();
        for (HolidayEnum holidayEnum : HolidayEnum.values()) {
            HolidayVO holidayVO = new HolidayVO();
            holidayVO.setName(holidayEnum.getName());
            holidayVO.setType(holidayEnum.getType());
            holidayVO.setFreePass(holidayEnum.getFreePass());
            holidayList.add(holidayVO);
        }
        return new ArrayList<>(holidayList);
    }

    /**
     * 获取指定是否免费通行的节假日
     * @param freePass
     * @return
     */
    public static List<HolidayVO> getHolidayListByFreePass(Boolean freePass) {
        return getHolidayList().stream()
                .filter(holidayVO -> holidayVO.getFreePass().equals(freePass))
                .collect(Collectors.toList());
    }

    /**
     * 获取指定类型的节假日名称
     * @param type
     * @return
     */
    public static String getNameByType(Integer type) {
        for (HolidayEnum holidayEnum : HolidayEnum.values()) {
            if (holidayEnum.getType().equals(type)) {
                return holidayEnum.getName();
            }
        }
        return null;
    }

}
